package tech.yunjing.log.dao;

import com.alibaba.fastjson.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.stereotype.Repository;
import tech.yunjing.base.core.common.persistence.Page;

import java.util.List;

/**
 * @author miou
 * Created by FYX on 2017/2/14 0014.
 */
@Repository
public class ApplicationLogDao extends MongodbBaseDao{

    @Autowired
    @Qualifier("mongoTemplate")
    private MongoTemplate mongoTemplate;

    public void save(JSONObject data){
        mongoTemplate.save(data.getJSONObject("data"),data.getString("applicationName"));
    }

    public long count(String applicationName){
        return mongoTemplate.count(new Query(),applicationName);
    }

    public List<JSONObject> findAll(String applicationName){
       return mongoTemplate.findAll(JSONObject.class,applicationName);
    }

    public List<JSONObject> findAllByPage(String applicationName,int pageNo,int pageSize){
        Query query = new Query();
        query.skip((pageNo - 1) * pageSize).limit(pageSize);
        return mongoTemplate.find(query,JSONObject.class,applicationName);
    }


}
